{% extends 'app01/admin/home.html' %}

{% block content %}
    <div class="panel panel-default">
        <div class="panel-heading">帖子管理</div>
        <div class="panel-body">

            {% for article in c_page %}
                <div class="media">
                    <div class="media-left">
                        <a href="#">
                            <img class="media-object" src="/media/{{ article.blog.userinfo.avatar }}" height="64" alt="...">
                        </a>
                    </div>
                    <div class="media-body">
                        <h4 class="media-heading"><a href="/app01/site/{{ article.blog.userinfo.username }}/article/{{ article.id }}?url={{ request.get_full_path_info }}" target="_blank">{{ article.title }}</a></h4>
                       <p> {{ article.desc }}</p>
                        <div class="pull-left"> <span style="color: #2e6da4"> 发表时间:{{ article.create_time }} &nbsp;&nbsp;&nbsp;&nbsp; 作者: {{ article.blog.userinfo.username }}</span>
                           &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a type="btn" style="color: indianred" class="del_btn" style="color: red" del_id="{{ article.id }}">删除</a> </div>
                    </div>
                </div>
                <hr>
            {% endfor %}


        </div>
    </div>
    {# 分页显示 #}
    <div class="pager">
        <nav aria-label="Page navigation">
            <ul class="pagination">
                {{ page_html }}
            </ul>
        </nav>
    </div>

{% endblock %}

{% block js %}
    <script>
        $('.del_btn').click(function () {
            //删除的二次确认
            let op = confirm('确认删除吗？')
            let del_id=$(this).attr('del_id')
              $.ajax({
            url:'',
            type:'post',
            data:{'del_id':del_id,'op':op},
            success:function (array) {
                if (array.code===100){
                    alert(array.msg)
                    window.location.reload()
                }
                else if( array.code===200 && op===true){
                    alert(array.msg)
                }

            }
        })
        })

//鼠标获取焦点时，错误信息不显示了。
        $('#id_confirm_pwd').focus(function () {
            $('#error').text('')

        })


    //修改密码的ajax请求

    $('#id_editer').click(function () {

        let old_pwd = $('#id_old_pwd').val()
        let new_pwd = $('#id_new_pwd').val()
        let comfir_pwd = $('#id_confirm_pwd').val()

        $.ajax({
            url:'/app01/set_password/',
            type: 'post',
            data:{'old_pwd':old_pwd,'new_pwd':new_pwd,'confirm_pwd':comfir_pwd},
            success:function (attr) {
                if(attr.code===1000){
                    alert(attr.msg)
                    window.location.reload()
                } else if(attr.code===2000){
                    $('#error').text(attr.msg)
                }else  if(attr.code===3000){
                    $('#error').text(attr.msg)
                }
            }
        })


    })


    </script>
{% endblock %}